home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / 92052tar.gz / 920528.tar / kiss.c < prev    next >
C/C++ Source or Header  |  1991-06-18  |  2KB  |  119 lines

  1. /* @(#) $Header: kiss.c,v 1.8 91/06/18 17:27:05 deyke Exp $ */
  2.  
  3. /* Routines for AX.25 encapsulation in KISS TNC
  4.  * Copyright 1991 Phil Karn, KA9Q
  5.  */
  6. #include "global.h"
  7. #include "mbuf.h"
  8. #include "iface.h"
  9. #include "kiss.h"
  10. #include "devparam.h"
  11. #include "slip.h"
  12. #include "asy.h"
  13. #include "ax25.h"
  14. #include "crc.h"
  15.  
  16. /* Send raw data packet on KISS TNC */
  17. int
  18. kiss_raw(iface,data)
  19. struct iface *iface;
  20. struct mbuf *data;
  21. {
  22.     register struct mbuf *bp;
  23.  
  24.     /* Put type field for KISS TNC on front */
  25.     if((bp = pushdown(data,1)) == NULLBUF){
  26.         free_p(data);
  27.         return -1;
  28.     }
  29.     bp->data[0] = PARAM_DATA;
  30.     if(iface->sendcrc){
  31.         bp->data[0] |= 0x80;
  32.         append_crc(bp);
  33.     }
  34.     /* slip_raw also increments sndrawcnt */
  35.     slip_raw(iface,bp);
  36.     return 0;
  37. }
  38.  
  39. /* Process incoming KISS TNC frame */
  40. void
  41. kiss_recv(iface,bp)
  42. struct iface *iface;
  43. struct mbuf *bp;
  44. {
  45.     char kisstype;
  46.  
  47.     if(bp && (*bp->data & 0x80)){
  48.         if(check_crc(bp)){
  49.             iface->crcerrors++;
  50.             free_p(bp);
  51.             return;
  52.         }
  53.     }
  54.     kisstype = PULLCHAR(&bp);
  55.     switch(kisstype & 0xf){
  56.     case PARAM_DATA:
  57.         ax_recv(iface,bp);
  58.         break;
  59.     default:
  60.         free_p(bp);
  61.         break;
  62.     }
  63. }
  64. /* Perform device control on KISS TNC by sending control messages */
  65. int32
  66. kiss_ioctl(iface,cmd,set,val)
  67. struct iface *iface;
  68. int cmd;
  69. int set;
  70. int32 val;
  71. {
  72.     struct mbuf *hbp;
  73.     char *cp;
  74.     int rval = 0;
  75.  
  76.     /* At present, only certain parameters are supported by
  77.      * stock KISS TNCs. As additional params are implemented,
  78.      * this will have to be edited
  79.      */
  80.     switch(cmd){
  81.     case PARAM_RETURN:
  82.         set = 1;        /* Note fall-thru */
  83.     case PARAM_TXDELAY:
  84.     case PARAM_PERSIST:
  85.     case PARAM_SLOTTIME:
  86.     case PARAM_TXTAIL:
  87.     case PARAM_FULLDUP:
  88.     case PARAM_HW:
  89.     case 12:                /* echo */
  90.     case 13:                /* rxdelay */
  91.         if(!set){
  92.             rval = -1;      /* Can't read back */
  93.             break;
  94.         }
  95.         /* Allocate space for cmd and arg */
  96.         if((hbp = alloc_mbuf(2)) == NULLBUF){
  97.             free_p(hbp);
  98.             rval = -1;
  99.             break;
  100.         }
  101.         cp = hbp->data;
  102.         *cp++ = cmd;
  103.         *cp = val;
  104.         hbp->cnt = 2;
  105.         slip_raw(iface,hbp);    /* Even more "raw" than kiss_raw */
  106.         rval = val;             /* per Jay Maynard -- mce */
  107.         break;
  108.     case PARAM_SPEED:       /* These go to the local asy driver */
  109.     case PARAM_DTR:
  110.     case PARAM_RTS:
  111.         rval = asy_ioctl(iface,cmd,set,val);
  112.         break;
  113.     default:                /* Not implemented */
  114.         rval = -1;
  115.         break;
  116.     }
  117.     return rval;
  118. }
  119.